layui.use('form', function(){
    var form = layui.form;
});

layui.use('element', function(){
    var element = layui.element;

});



function getQueryVariable() {
    var query = window.document.location.href.toString();
    var query = query.split("?");
    var vars = query[1].split("&");
    var res = [];
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        res[pair[0]] = pair[1];
    }
    return res;
}

// 获取 url参数
function GetRequest(urlStr) {
    if (typeof urlStr == "undefined") {
        var url = decodeURI(location.search); //获取url中"?"符后的字符串
    } else {
        var url = "?" + urlStr.split("?")[1];
    }
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

// 判断字符是否为空的方法
function isEmpty(obj){
    if(typeof obj == "undefined" || obj == null || obj == ""){
        return true;
    }else{
        return false;
    }
}



// 休眠时间
function sleep(delay) {
    var start = (new Date()).getTime();
    while ((new Date()).getTime() - start < delay) {
        continue;
    }
}


// 自带页码重构自己随机调用
function pageRestructure(pageName,pageCount,pageNumber,name,type,state,remarks) {
    // 清空一下节点
    $(pageName).empty();
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;
        laypage.render({
            jump: function(obj, first){
                datalist(obj.curr, obj.limit,name,type,state,remarks) // 处理列表信息
            },
            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
            limits:[20,40,60,80,100],
            elem: pageName,
            count: pageCount, //数据总数
            limit:pageNumber
        })
    })
}

// url验证
function IsURL(str_url){
    var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
        + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@
        + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
        + "|" // 允许IP和DOMAIN（域名）
        + "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
        + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
        + "[a-z]{2,6})" // first level domain- .com or .museum
        + "(:[0-9]{1,4})?" // 端口- :80
        + "((/?)|" // a slash isn't required if there is no file name
        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
    var re=new RegExp(strRegex);
    //re.test()
    if (re.test(str_url)){
        return (true);
    }else{
        return (false);
    }
}

// 勾选全部的按钮
function checked_input_all(c,name) {
    var arr= document.getElementsByName(name);
    if(c){                //是否全选
        for (var i = 0; i < arr.length; i++) {
            arr[i].checked= true;//选中
        }
    }else{
        for (var i = 0; i < arr.length; i++) {
            arr[i].checked= false;//不选中
        }
    }

}